//
//  ISAACRegistPSWController.m
//  FireBird
//
//  Created by Isaac on 2018/5/2.
//  Copyright © 2018年 Isaac. All rights reserved.
//

#import "ISAACRegistPSWController.h"

@interface ISAACRegistPSWController ()
@property (nonatomic, strong)UITextField *accountText;
@property (nonatomic, strong)UITextField *pswText;
@end

@implementation ISAACRegistPSWController
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self addTitleViewWithTitle:@"注册"];

    
    [self setupViews];
    
}
- (void)setupViews {
    
    self.accountText = [MyControlUilt createTextFieldWithFrame:CGRectMake(LEFTSPACE, 120, SCREEN_WIDTH-LEFTSPACE*2, 30) Title:@"请输入密码" TextColor:kTextColorTwo SuperView:self.view Font:FONT14 BackColor:kBackGColor];
    
    self.pswText = [MyControlUilt createTextFieldWithFrame:CGRectMake(LEFTSPACE, CGRectGetMaxY(_accountText.frame), SCREEN_WIDTH-LEFTSPACE*2-100, 30) Title:@"请确认密码" TextColor:kTextColorTwo SuperView:self.view Font:FONT14 BackColor:kBackGColor];
    
    UIButton *confirmBtn = [MyControlUilt createButtonWithFrame:CGRectMake((SCREEN_WIDTH-150)/2.0, CGRectGetMaxY(_pswText.frame)+40, 150, 30) Title:@"注册" TiTleColor:kWhiteColor SuperView:self.view Font:FONT14 BackColor:kRedColor];
    confirmBtn.layer.masksToBounds = YES;
    confirmBtn.layer.cornerRadius = 21;
    [confirmBtn addTarget:self action:@selector(handleConfirmLogin:) forControlEvents:UIControlEventTouchUpInside];
 
    
}


- (void)handleConfirmLogin:(UIButton *)sender {
    if (_accountText.text.length < 6 || _pswText.text.length < 6) {
        [SVProgressHUD showErrorWithStatus:@"密码输入有误"];
        return;
    }
    if (![_accountText.text isEqualToString: _pswText.text]) {
        [SVProgressHUD showErrorWithStatus:@"两次密码不一致"];
        return;
    }
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"phone"] = _phone;
    param[@"password1"] = _pswText.text;        //[TTConfig MD5ByAStr:_pswText.text];
    param[@"password2"] = _accountText.text;    //[TTConfig MD5ByAStr:_accountText.text];
    param[@"verify_code"] = _verify_code;
//    param[@"ACOS"] = @"iOS";
    
    //  去获取验证码
    __weak typeof(self) weakself = self;
    [TTServerTool postDictionaryResult:API_user_reg param:param isNeedToken:YES complete:^(BOOL network, TTPublicResult * result, NSError * error) {
        
        if (network) {
            
            if (result) {
                
                if([result.ErrorCode isEqualToString:@"0"]){
                    [weakself.pswText becomeFirstResponder];
                    [weakself.navigationController popToRootViewControllerAnimated:YES];
                    
                }else{
                    [SVProgressHUD showErrorWithStatus:result.ErrorMsg];
                    //倒计时结束，关闭
                   
                }
                
            }else{
                [SVProgressHUD showErrorWithStatus:@"暂无数据"];
                //倒计时结束，关闭
               
            }
            
        }else{
            [SVProgressHUD showErrorWithStatus:@"网络错误"];
            //网络链接失败
            //倒计时结束，关闭
          
        }
        
    }];
}

@end
